<?php
include_once '../../Config/config.php';
include_once '../../Config/conexion.php';
include_once '../../Model/Paper.php';

include_once '../../Model/Track.php';
include_once '../../Model/Idioma.php';
include_once '../../Model/Rol.php';
include_once '../../Model/Revisor.php';

$usuario = Util::ObtenerSession();
$track_id = "";					
if($usuario->Roles[0]->Id == 6){
	$track_id = $usuario->Track->Id;
}

$idrol = isset($_REQUEST["idrol"])?$_REQUEST["idrol"]:"";
$idpais = isset($_REQUEST["idpais"])?$_REQUEST["idpais"]:"";
?>
	<script>
		$(document).ready(function(){
			$(".ficha").click(function(){
				//alert(123);
				
				var obj = $(this);				
				$.ajax({
					url:URL_PAGE+"Modulos/Usuarios/Ficha.php",
					data : {idusuario : obj.attr("data-id")},
					type:"post",
					success:function(data){
						$("#window-modal").html(data);
						$("#window-modal").dialog(
							{
								autoOpen: true,
								width: 820,
								maxheight: 600,
								resizable: false,
								modal: true,
								show: 'slide',
								hide: 'slide',
								position: ["center",100],
								title: "Agregar Usuario",
								open: function (event, ui) {
									var parent = $(this);
									$('.ui-widget-overlay').click(function () {
										parent.dialog("close");
									})                        
								},
								close: function (event, ui) {                        
								}
							}
						)
					}
				});
			
			})
		});
	</script>

	<p><a href="List_excel.php">Exportar</a></p>
	<table class="tabla-basica">	
	<thead>
		<tr>
			<th>#</th>
			<th>
				Nombre completo
			</th>
			<th>
				Instituci&oacute;n
			</th>			
			<th>
				Pa&iacute;s
			</th>
			
			<?php
			if($idrol != "1"){
			?>			
			<th>
				Track
			</th>
			<?php
			}
			?>			
			<th>
				Rol
			</th>	
     
            <th>
				
			</th>
		<!--	<th>
			</th>-->
		</tr>
	</thead>
	<tbody>	
		<?php
								
				$lista = Usuario::ListarPorRol($idrol,0,$idpais);	

				$fila = 0;
				foreach($lista as $row){
					
					if($idrol == 2){
						$revisor = Revisor::Obtener($row->IdUsuario);
						$tracks = explode("," ,$revisor->Tracks);
						if($track_id != ""){
							if(!in_array($track_id, $tracks)){
								continue;
							}
						}
					}
					$fila++;
		?>
				<tr>
					<td><?php echo $fila;?></td>
					<td>
						<?php echo Util::FormatoHtml($row->Nombres)?> <?php echo Util::FormatoHtml($row->Paterno)?> <?php echo Util::FormatoHtml($row->Materno)?>
						<br>
						<?php echo $row->Email?>
					</td>
					<td>
						<?php
							if($row->Institucion != null)
							{
						?>
						<?php echo Util::FormatoHtml($row->Institucion->Nombre)?>
						<?php
							}
						?>
					</td>					
					<td>
						<?php echo Util::FormatoHtml($row->Pais->Nombre)?>
					</td>
					
						<?php
							if($idrol != "1"){
						?>
						<td>
							<?php
								$revisor = Revisor::Obtener($row->IdUsuario);
								
								//print_r($revisor);
								if($revisor->Tracks == ""){
									if($row->Track){
							?>
							<?php echo Util::FormatoHtml($row->Track->Nombre)?>
							<?php 
									}
								}else{
									$tracks = explode("," ,$revisor->Tracks);
									foreach($tracks as $item){
										//echo $item;
										$track = Track::Obtener($item);
										echo Util::FormatoHtml($track->Nombre)."<br />";
									}
								}
							?>
						</td>
						<?php
							}
						?>
										
					<td>
						<?php echo $row->Rol->Nombre?>
					</td>

                    <td>
                    	<div style="float:left; width:60px; text-align:center; color:#025A8D; padding-top:5px">
						<img src="<?php echo INI_URL?>/Content/template01/images/editar.png"
						data-idusuario="<?php echo $row->IdUsuario?>"
						title="Editar"  class="pointer editar" /> <br />Editar
						</div>
						<?php  
							if($row->Rol->Id == 2){
						?>	
                        <div style="float:left; width:60px; text-align:center; color:#025A8D; padding-top:5px">					
						<img src="<?php echo INI_URL?>/Content/template01/images/ficha.png"
						data-id="<?php echo $row->IdUsuario?>"
						title="Ver ficha"
						class="pointer ficha" /> <br />Ver ficha
                        </div>
						<?php
						}
						?>
                    </td>
				<!--	<td>
						<div style="text-align:center; float:right">
						<a href="#" class="eliminarUsuario"
						data-idusuario="<?php echo $row->IdUsuario?>">
							<img src="<?php echo INI_URL?>/Content/template01/images/trash1.png" /><br />Eliminar
						</a>
						</div>
					</td>-->
				</tr>
		<?php
				}
		?>
		
	</tbody>
	</table>
	